package com.wey.springboot.controller;

import com.wey.springboot.bean.Account;
import com.wey.springboot.service.AccountService;
import com.wey.springboot.util.CommonResult;
import com.wey.springboot.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ResponseBody
public class AccountController {
  @Autowired
  private AccountService accountService;
  @Autowired
  private StringUtil stringUtil;

  @RequestMapping("/account/get")
  public CommonResult<Account> get(@RequestParam("id") Integer id) {
    return CommonResult.success(accountService.get(id));
  }

  @RequestMapping("/account/list")
  public CommonResult<List<Account>> list() {
    return CommonResult.success(accountService.list(), "获取账户列表成功");
  }

  @RequestMapping("/account/insertBatch")
  public CommonResult<Integer> saveBatch(@RequestParam(defaultValue = "1") Integer count) {
    boolean resule = accountService.saveBatch(count);
    return resule ? CommonResult.success(1, "添加账户成功") : CommonResult.fail("添加账户失败");
  }

  @RequestMapping("/account/count")
  public CommonResult<Integer> count() {
    return CommonResult.success(accountService.count());
  }
}
